package willevaluate.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.xuegengwang.xuegengwang.R;

import java.util.ArrayList;

import willevaluate.bean.ExpertEvaluateCollegeBean;

/**
 * Created by Administrator on 2017/5/22.
 */

public class ExpertEvaluateCompleteCollegeAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<ExpertEvaluateCollegeBean> arrayList;
    private MyOnClick myOnClick;
    private OnDeleteListener onDeleteListener;

    public ExpertEvaluateCompleteCollegeAdapter(Context context, ArrayList<ExpertEvaluateCollegeBean> arrayList, MyOnClick myOnClick, OnDeleteListener onDeleteListener) {
        this.context = context;
        this.arrayList = arrayList;
        this.myOnClick = myOnClick;
        this.onDeleteListener = onDeleteListener;
    }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        MyHolder myHolder;

        if (convertView == null) {
            myHolder = new MyHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.expert_evaluate_complete_college_item, null);
            myHolder.expert_evaluate_complete_info_id = (TextView) convertView.findViewById(R.id.expert_evaluate_complete_info_id);
            myHolder.expert_evaluate_complete_college_college = (TextView) convertView.findViewById(R.id.expert_evaluate_complete_college_college);
            myHolder.expert_evaluate_complete_college_edit = (ImageView) convertView.findViewById(R.id.expert_evaluate_complete_college_edit);
            myHolder.expert_evaluate_complete_college_delete = (ImageView) convertView.findViewById(R.id.expert_evaluate_complete_college_delete);
            convertView.setTag(myHolder);
        } else {
            myHolder = (MyHolder) convertView.getTag();
        }
        myHolder.expert_evaluate_complete_info_id.setText("" + (position + 1));
        if (!TextUtils.isEmpty(arrayList.get(position).getCollegeName())) {
            myHolder.expert_evaluate_complete_college_college.setText(arrayList.get(position).getCollegeName());
        }
        myHolder.expert_evaluate_complete_college_edit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                myOnClick.OnEditListener(position);
            }
        });
        myHolder.expert_evaluate_complete_college_delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onDeleteListener.onDeleteListener(position);
            }
        });

        return convertView;
    }

    private class MyHolder {
        TextView expert_evaluate_complete_info_id;
        TextView expert_evaluate_complete_college_college;
        ImageView expert_evaluate_complete_college_edit;
        ImageView expert_evaluate_complete_college_delete;
    }

    public interface MyOnClick {
        void OnEditListener(int position);
    }

    public interface OnDeleteListener {
        void onDeleteListener(int position);
    }
}
